package com.spzx.product.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.spzx.common.core.domain.R;
import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.security.annotation.InnerAuth;
import com.spzx.product.domain.ProductDetails;
import com.spzx.product.mapper.ProductDetailsMapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Tag(name = "商品详情图模块")
@RequestMapping("/details")
public class ProductDetailsController extends BaseController {
    @Resource
    ProductDetailsMapper productDetailsMapper;
    @InnerAuth
    @Operation(summary = "内部调用接口：根据productId查询商品详情图列表")
    @GetMapping("getdetails/{productId}")
    public R<ProductDetails>getDetails(@PathVariable("productId")Long productId){
        //生成的sql语句为select * from product_details where product_id = ? limit 1
        return R.ok(productDetailsMapper.selectOne(Wrappers.lambdaQuery(ProductDetails.class).eq(ProductDetails::getProductId,productId).last("limit 1")));
    }
}
